package cn.tedu.dental.admin.controller;

import cn.tedu.dental.admin.pojo.dto.DoctorLoginParam;
import cn.tedu.dental.admin.pojo.dto.DoctorQuery;
import cn.tedu.dental.admin.pojo.dto.DoctorSaveParam;
import cn.tedu.dental.admin.pojo.vo.DoctorVO;
import cn.tedu.dental.admin.service.AdminService;
import cn.tedu.dental.base.response.JsonResult;
import cn.tedu.dental.user.pojo.dto.UserLoginParam;
import cn.tedu.dental.user.pojo.dto.UserQuery;
import cn.tedu.dental.user.pojo.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/admin")
public class AdminController {

    @Autowired
    AdminService adminService;

    @GetMapping("/doctor/select")
    public JsonResult selectDoctor(DoctorQuery doctorQuery) {
        log.debug("查询医生:doctorQuery={}", doctorQuery);
        List<DoctorVO> list = adminService.selectDoctor(doctorQuery);
        return JsonResult.ok(list);
    }

    @GetMapping("/user/select")
    public JsonResult selectUser(UserQuery userQuery) {
        log.debug("查询用户:userQuery={}", userQuery);
        List<UserVO> list = adminService.selectUser(userQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("login")
    public JsonResult doctorLogin(DoctorLoginParam doctorLoginParam) {
        DoctorVO doctorVO = adminService.doctorLogin(doctorLoginParam);
        return JsonResult.ok(doctorVO);
    }

    @PostMapping("save")
    public JsonResult saveDoctor(DoctorSaveParam doctorSaveParam) {
        log.debug("保存用户,userSaveParam={}", doctorSaveParam);
        adminService.saveDoctor(doctorSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("selectByDoctorId")
    public JsonResult editDoctor( DoctorQuery doctorQuery) {
        log.debug("查询参数doctorQuery={}", doctorQuery);
        DoctorVO doctorVO = adminService.selectByDoctorId(doctorQuery);
        return JsonResult.ok(doctorVO);
    }

    @PostMapping("/deleteDoctor/{doctorId}")
    public JsonResult deleteUser(@PathVariable Long doctorId){
        log.debug("删除医生,userId={}",doctorId);
        adminService.deleteDoctor(doctorId);
        return JsonResult.ok();
    }

    @PostMapping("/resetDoctorPassword/{doctorId}")
    public JsonResult resetDoctorPassword(@PathVariable Long doctorId){
        log.debug("医生,doctorId={}",doctorId);
        adminService.resetDoctorPassword(doctorId);
        return JsonResult.ok();
    }
}
